package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * e签宝流程状态(0-草稿,1-签署中,2-完成,3-撤销,4-终止（签署流程设置了文件有效截至日期，到期后触发),5-过期（签署截至日志到期后触发),7-拒签)
 * 创建时间 2020/6/24 4:31 PM
 * 修改时间 2020/6/24 4:31 PM
 * @author chy
 */
@Getter
public enum EsignFlowStatusEnum {
    UNSIGNED(-1, "enum.esignFlowStatus.name.unsigned"),
    DRAFT(0, "enum.esignFlowStatus.name.draft"),
    SIGNING(1, "enum.esignFlowStatus.name.signing"),
    COMPLETE(2, "enum.esignFlowStatus.name.complete"),
    UNDO(3, "enum.esignFlowStatus.name.undo"),
    TERMINATION(4, "enum.esignFlowStatus.name.termination"),
    EXPIRED(5, "enum.esignFlowStatus.name.expired"),
    REFUSAL(7, "enum.esignFlowStatus.name.refusal"),

    UNKNOWN(-10, "enum.callStatus.name.unknown"),

    ;

    /** 枚举值 -- */
    private final int code;
    /** 枚举信息--中文名称 */
    private final String    name;

    EsignFlowStatusEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 获取全部枚举
     *
     * @return List<EsignFlowStatusEnum>
     */
    public static List<EsignFlowStatusEnum> getAllEnum() {
        List<EsignFlowStatusEnum> list = new ArrayList<>();
        for (EsignFlowStatusEnum cache : values()) {
            list.add(cache);
        }
        return list;
    }

    /**
     * 根据alias获取枚举
     * @return
     */
    public static EsignFlowStatusEnum getByCode(int code) {
        for (EsignFlowStatusEnum cache : values()) {
            if (code == cache.getCode()) {
                return cache;
            }
        }
        return UNKNOWN;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
